<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  <!--  <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content=""> -->
    <link rel="shortcut icon" href="../docs-assets/ico/favicon.png">
	
	<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="../js/underscore-1.1.6.js"></script>
	<script src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script>
	
	

    <title>Sign in</title>

    <!-- Bootstrap core CSS -->
    <link href="../dist/css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../dist/css/signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../docs-assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

      <div id="user-info" hidden>
        Enregistré comme  <span id="us"> </span>
		<a href="#" class="log-out">Déconnexion</a>
      </div>
	  
    <div class="container">

      <div class="form-signin" role="form">
        <h2 class="form-signin-heading">Authentification</h2>
		<input type="text" id="login-username" class="form-control" placeholder="Username" required autofocus>
        <input type="password" id="login-password" class="form-control" placeholder="Password" required>
        <button id="login" class="btn btn-lg btn-primary btn-block" >Connexion</button>
      </div>
	
	
    </div> <!-- /container -->
	<script >
	$( document ).ready(function() {
		Parse.$ = jQuery;
		Parse.initialize("lken7qlOOU6DnGkQddYiIIVTTGBVGt8cHsTh0mN6", "lVOSFDfYALex78xE7WdpLadiZl61hUe1VrbnLA73");


		if (Parse.User.current()) {
		  $("#us").text(Parse.User.current().get("username"));
		  $("#user-info").show();
		} else {
			$("#user-info").hide();
		}
		
		$("#login").click(function(){
			
			if (Parse.User.current()) {
			  alert("Vous êtes déjà connecté");
			} else {
		
				var username = $("#login-username").val();
				var password = $("#login-password").val();
				Parse.User.logIn(username, password, {
					success: function(user) {
					alert("Bien connecté");
					$("#us").text(Parse.User.current().get("username"));
					$("#user-info").show();
					$("#redirect").show();
					window.setTimeout("location=('../index2.html');",5000);
					},

					error: function(user, error) {
					  alert("Mal connecté :"+user+" \nError:"+error);
					  //Parse.User.logOut();
					  //location.reload();
					}
			    });
			}
		});
		$(".log-out").click(function(){
			
			Parse.User.logOut();
			$("#user-info").hide();
		});
	});
	</script>
	
    <!-- Bootstrap core JavaScript
	<script src="../js/jquery-2.0.3.js"></script>
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
  </body>
</html>
